﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IFSModel;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        //Members_play c = new Members_play();
        //decimal point = 0;
        //decimal star = 0;
        //bool ch;

        //ch = c.calMatchPoint(out point, out star);

         //decimal star = -5;
         //decimal point = -1;

         //var c = star < 0 ? (point.Equals(-1) ? star * -1 : 0) : star;
        
    }

     

    protected void Button1_Click(object sender, EventArgs e)
    {
       bool ret = calMatchPoint(ddlhandycap.SelectedValue,ddlselectteam.SelectedValue,txtscorea.Text,txtscoreb.Text,txtprice.Text,Convert.ToInt32(txtstar.Text));
    }

    public bool calMatchPoint(string Current_TeamHandicap, string Selectteam, string _ScoreA, string _ScoreB, string Current_PriceHandicap, int StarBet)
    {

        //Rdiff = teamAscore - teamBscore
        //Diff = rDiff - Handicap
        //Win full  : Diff >= 0.5
        //Win half  : Diff = 0.25
        //Draw      : Diff = 0
        //Lost full : Diff <= -0.5
        //Lost half : Diff = -0.25

        decimal Rdiff = 0;
        decimal Diff = 0;
        decimal Calfinalpoint = 0;
        decimal Calstar = 0;
          
        //ทีมเยือนต่อเมื่อไหร่แม่งสลับผลทันที 

        if (Current_TeamHandicap.ToString().ToLower() == "livea" && Selectteam.ToString().ToLower() == "livea") // selected team A ทีมต่อ
        {
            Rdiff = (Convert.ToInt32(_ScoreA) - Convert.ToInt32(_ScoreB));
            Diff = Rdiff - Convert.ToDecimal(Current_PriceHandicap);
        }
        else if (Current_TeamHandicap.ToString().ToLower() == "livea" && Selectteam.ToString().ToLower() == "liveb") // selected team A ทีมรอง
        {
            Rdiff = (Convert.ToInt32(_ScoreB) - Convert.ToInt32(_ScoreA));
            Diff = Rdiff + Convert.ToDecimal(Current_PriceHandicap);
        }
        else if (Current_TeamHandicap.ToString().ToLower() == "liveb" && Selectteam.ToString().ToLower() == "liveb") // selected team b ทีมต่อ
        {
            Rdiff = (Convert.ToInt32(_ScoreB) - Convert.ToInt32(_ScoreA));
            Diff = Rdiff - Convert.ToDecimal(Current_PriceHandicap);
        }
        else if (Current_TeamHandicap.ToString().ToLower() == "liveb" && Selectteam.ToString().ToLower() == "livea") // selected team a ทีมรอง
        {
            Rdiff = (Convert.ToInt32(_ScoreA) - Convert.ToInt32(_ScoreB));
            Diff = Rdiff + Convert.ToDecimal(Current_PriceHandicap);
        }
        //==================================================================

        if (Convert.ToDouble(Diff) >= 0.5) // Winfull
        { 
            Calfinalpoint = 2;
            Calstar = Convert.ToDecimal(StarBet) + Convert.ToDecimal(StarBet); 
        }
        else if (Convert.ToDouble(Diff) == 0.25) // Winhalf
        { 
            Calfinalpoint = 1;
            Calstar = Convert.ToDecimal(StarBet) + (Convert.ToDecimal(StarBet) / 2); 
        }
        else if (Convert.ToDouble(Diff).Equals(0)) //Draw
        {
            Calfinalpoint = 0;
            Calstar = Convert.ToDecimal(StarBet);
        }
        else if (Convert.ToDouble(Diff) <= -0.5) // Lostfull
        { 
            Calfinalpoint = -2;
            Calstar = (Convert.ToDecimal(StarBet)) * -1; 
        }
        else if (Convert.ToDouble(Diff) == -0.25) // Losthalf
        { 
            Calfinalpoint = -1;
            Calstar = (Convert.ToDecimal(StarBet) / 2) * -1; 
        }


        txtresultpoint.Text = Calfinalpoint.ToString();
        txtresultstar.Text  =  Calstar.ToString();

        return true;

    }
}